﻿	var paperInfoForm = new Ext.FormPanel({
		id:"paperInfoForm",
		width:500,
		frame:false,
		border:false,
		bodyStyle:"padding:5px 5px 0",
		waitMsgTarget:true,// true的意思是说表单提交时的等待信息在这个表单之内显示，而不是弹出框(进度条形式的)
		labelAlign:"right",
		labelPad : 10,// 标签与字段录入框之间的空白
		defaults:{width:230,disabled:true},
		defaultType:"textfield",
		items:[{
				fieldLabel:"已上传论文",
				name:"title"
			},{
				fieldLabel:"论文状态",
				name:"state"
			}],
		buttonAlign:"center",
		buttons:[{
			align:"left",
			text:"上传新论文",
			id:"uploadBtn",
			handler:function(){
				new showUploadWindowFn();
			}
		}]
	});
	
	var paperUploadForm = new Ext.FormPanel({
		// renderTo: 'fi-form',
		id:"paperUploadForm",
		fileUpload : true,
		width:400,
		frame : true,
		border : false,
		//title : '论文上传',
		autoHeight : true,
		bodyStyle : 'padding: 10px 10px 0',
		//labelAlign:"right",
		labelPad : 10,// 标签与字段录入框之间的空白

		defaults : {
			width:230,
			anchor : '95%',
			allowBlank : false,
			msgTarget : 'side'
		},
		items : [{
					xtype : 'textfield',
					name : 'title',
					fieldLabel : '标题'
				}, {
					xtype : 'fileuploadfield',
					id : 'form-file',
					emptyText : '选择文件',
					fieldLabel : '文件',
					name : 'upload',
					buttonText : '',
					buttonCfg : {
						iconCls : 'upload-icon'
					}
				}]
	});
		
	var showUploadWindowFn = function(){
		new Ext.Window({
			id:"uploadWindow",
			title:"上传论文",
			width:400,
			autoHeight:true,
			resizable:false,// 不可以调整大小
			draggable:false,// 不可移动
			modal:true,// 设置此Window为模式窗口,
			animateTarget:"uploadBtn",// 当指定一个id或元素,window打开时会与元素之间产生动画效果
			items:[
				new Ext.form.FormPanel(paperUploadForm)
			],
			buttonAlign:"center",
			minButtonWidth:60,
			buttons : [{
						text : '上传',
						handler : function() {
							Ext.getCmp("paperUploadForm").getForm().submit({
										url: "paper/paperAddAction",
										method: "POST",
										waitMsg : '论文上传中',
										success : function() {
											Ext.Msg.alert("上传成功", "论文上传成功","msg-box-success");
											Ext.getCmp("uploadWindow").close();
											new showPaperInfoFn();//刷新
										},
										failure:function(form,action){			// 提交指失败进处理的方法
											Ext.Msg.alert("上传失败","论文上传成功，请核对","msg-box-error");
										}
									});
						}
					}, {
						text : '取消',
						handler : function() {
							Ext.getCmp("uploadWindow").close();
						}
					}]
		}).show();
	}
	var showPaperInfoFn = function(){
			var _form = Ext.getCmp("paperInfoForm").getForm();//根据id获取form
			_form.reader =  new Ext.data.JsonReader({
									root:'graduate'
								},[//{name:表单元素，type:数据类型,mapping:server元素}
							       {name:"title",type:"string",mapping:"paper",convert:function(v){return v?v.title:"暂未上传"}},
							       {name:"state",type:"string",mapping:"paper",convert:function(v){return v?v.strState:null}}
/*							       {name:"commentContent",type:"string",mapping:"comment",
							       		convert:function(v){return v?v.content:null}}*/
							    ]);
			_form.load({url:"paper/paperInfoAction!graduateExecute.action",
						waitMsg: '正在载入数据...',
						success:function(form, action){
							// Ext.example.msg("提示","数据加载成功……","msg-box-success");
						},
						failure:function(){
							Ext.example.msg("异常","数据加载失败","msg-box-error");
						}						
					});
	}
	
	/** *************定义评论列表数据************ */
	var commentManageProxy = new Ext.data.HttpProxy({url: "paper/paperInfoAction!graduateExecute"});
	var comment = Ext.data.Record.create([
		{name: "teacherName", type: "string", mapping: "teacher.name"},
		{name: "time", type: "string", mapping: "time"},
		{name: "content", type: "string", mapping: "content"},
		//{name: "email", type: "string", mapping: "email"}
	]);
	var commentManageReader = new Ext.data.JsonReader(
		{/*totalProperty: "totalProperty",*/ root: "commentList"},
		comment
	);
	var commentManageStore = new Ext.data.Store({
		proxy: commentManageProxy,
		reader: commentManageReader
		//autoLoad:true
	});
	
	// 列模型
	var cm = new Ext.grid.ColumnModel([
		new Ext.grid.RowNumberer(),
		{header: "评阅老师", width: 100, dataIndex: "teacherName"},
		{header: "评阅时间", width: 140,dataIndex: "time",sortable:true},
		{header: "评阅意见", width: 180,dataIndex: "content"}
	]);

	var bbar = new Ext.PagingToolbar({
		store: commentManageStore,
	});
	
		/** ***************定义主体panel***************** */
	var commentManageGrid = new Ext.grid.GridPanel({
		//width: 400,
		border:true,
		autoHeight:true,
		cm: cm,
		bbar:bbar,
		store: commentManageStore
	});		



	Ext.onReady(function() {
		
		Ext.BLANK_IMAGE_URL = "extjs/resources/images/default/s.gif";
		Ext.QuickTips.init();
		paperInfoForm.render(Ext.get("paperInfo"));
		commentManageGrid.render(Ext.get("commentList"));
		showPaperInfoFn();
		commentManageStore.load();	
	});